﻿using System;
using System.Data.Common;
using System.Numerics;
 
namespace Prime_Factor
{
    class Factor
    {

        static bool Is_Prime(int i)
        {
            for (int j = 2; j * j <= i; j++)
            {
                if (i % j == 0)
                    return false;
            }
            return true;
        }

        static void Factorize(ref int i, ref int[] a)
        {
            int[] factors = new int[100];
            int index = 0;
            for (int j = 2; j < i; j++)
            {
                if (i % j == 0 && Is_Prime(j))
                {
                    factors[index] = j;
                    index++;
                }
            }
            a= factors;
        }
        static void Main()
        {
         int num2;
        Console.WriteLine("Enter a number to find its prime factors: ");
            
           string num = Console.ReadLine();

            while(!(int.TryParse(num, out num2))) 
            {
                Console.WriteLine("Invalid input. Please enter a number.");
                Console.WriteLine("Enter a number to find its prime factors: ");
                num = Console.ReadLine();
            }
            int[] factor= { 0 };
            Factorize(ref num2,ref factor);
            for (int i = 0; i < factor.Length; i++)
            {
                if (factor[i]!=0)
                Console.WriteLine($"{factor[i]}");
            }
            return;
        }
    }
}

